const Router = require('koa-router');
const router = new Router();
const gradeController = require('../controllers/grade.controller');
const authMiddleware = require('../middlewares/auth.middleware');

// 成绩相关API路由

// 获取所有成绩列表
router.get('/', authMiddleware.authenticateToken, gradeController.getAllGrades);

// 获取单个成绩信息
router.get('/:id', authMiddleware.authenticateToken, gradeController.getGradeById);

// 创建新成绩记录
router.post('/', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), gradeController.createGrade);

// 更新成绩信息
router.put('/:id', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), gradeController.updateGrade);

// 删除成绩记录
router.delete('/:id', authMiddleware.authenticateToken, authMiddleware.authorize(['admin']), gradeController.deleteGrade);

// 获取学生的所有成绩
router.get('/student/:studentId', authMiddleware.authenticateToken, gradeController.getStudentGrades);

// 获取班级的成绩列表
router.get('/class/:classId', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), gradeController.getClassGrades);

// 获取科目成绩统计
router.get('/subject/:subject/stats', authMiddleware.authenticateToken, authMiddleware.authorize(['admin', 'teacher']), gradeController.getSubjectStats);

// 根据学期获取成绩
router.get('/term/:term', authMiddleware.authenticateToken, gradeController.getGradesByTerm);

module.exports = router;